export default {
	init: () => {
		// #ifdef APP-PLUS
		var req = { //升级检测数据
		    "appid": plus.runtime.appid,  
		    "version": plus.runtime.version,  
		    "imei": plus.device.imei,  
		    "plus":plus.os.name  
		};
		this.$request.post(this.$api.common.appupload,req,'form').then(res => {
			if(res.success) {
				
			    //需要更新，提示用户  
			    plus.nativeUI.confirm(res.msg, function(event) {  
			        if(0 == event.index) { //用户点击了“立即更新”按钮  
			            plus.runtime.openURL(res.url);  
			        }
			    }, res.title, ["立即更新", "取　　消"]);  
			}
		})
		// #endif
	},

	getClient: (callback) => {
		// #ifdef APP-PLUS
		let clientInfo = plus.push.getClientInfo();  //获取 clientID
		uni.setStorageSync('clientid', clientInfo.clientid)
		// #endif

	},

}
const pushHandle = (msg) => {
	if (typeof (msg.payload )=='string') {  //如果是字符串，表示是ios创建的  要转换一下
		msg.payload=JSON.parse(msg.payload )
	}
	if(!msg) return false;
	plus.runtime.setBadgeNumber(0); //清除app角标
	
	//下面的代码根据自己业务来写 这里可以写跳转业务代码
	//跳转到tab
	if (msg.payload.pathType == '1') {
		uni.switchTab({
			url: msg.payload.url
		})
	}
	//跳转到详情
	if (msg.payload.pathType == 0) {
		let url = msg.payload.url
		if (msg.payload.args) {
			url = url + '?listId=' + msg.payload.args
		}
		console.log(url);
		uni.navigateTo({
			url: url
		})
	}
}
